#!/usr/bin/env bash
set -u

echo "Regenerating expected links in documentation"

DOCS_DIR=$1 # The location of documentation is passed as a first parameter

EXPECTED_LINKS_FILE=$2 # The location of expected-links.txt is passed as a second parameter

pushd $DOCS_DIR > /dev/null # Go to docs dir but remember previous location
# We need to go to docs dir to make find return correct relative paths
find . -type f -name "*.html" | (popd > /dev/null; LC_ALL=C sort > $2;)
# We list every html file in documentation, then sort it and finally write it to the expected links list file.
# Before writing we need to popd to return to the previous location because we don't have relative path to the expected links file.

